<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<style type="text/css">
.backcolor{
background-color: #5cacee;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="../header.jsp"></jsp:include>
<title>用户信息</title>
</head>
<body>
<div class="contextBox">
<form name="form" action="<%=request.getContextPath()%>/riskManage/getwhkList.do?currentPage=1" method="post">
		<table class="TableList" width="100%" align="center">
		   <tbody><tr class="TableContent">
		   <td >
		          用户姓名：<input type="text"  class="BigInput" id="userName" name="userName"  value="${userName}">
		        
		    </td>
		     </tr>
		</tbody></table>
		
		<div>
		<table>
		<tbody>
		<tr>
		<td>
		<input type="submit" value="搜索"/>
		<input type="button"   onclick="clearData()" value="清空"/>
		</td>
		</tr>
		</tbody>
		</table>
		</div>
		<table id="userinfotable" class="table" width="100%" align="center" border="0" cellspacing="0" cellpadding="0" class="list_table">
	    <tbody>
	    <tr>
	    <th width="1%" class="list_title" align="center"><input type="checkbox" name="allbox" id="allbox_for_requ"></th>
		
		<th width="10%" class="list_title" align="center"><b>客户姓名</b></th>
		<th width="14%" class="list_title" align="center"><b>逾期天数</b></th>
		<th width="8%" class="list_title" align="center"><b>催收金额</b></th>
		<th width="8%" class="list_title" align="center"><b>手机号码</b></th>
		
		
	  </tr>
		<c:forEach items="${datalist}" var="ui">		
		<tr>
		<td class="list_value" align="center">
		&nbsp;<input type="checkbox" name="requ_select" id="requ_checkbox_${ui.orderNo}" value="${ui.orderNo}">
		</td>
	    <td  align="left"><span>${ui.userName}</span></td>
	    <td  align="left"><span>${ui.yqday }</span></td>
		<td  align="right"><span>${ui.payMoney }</span></td>
		<td  align="center"><span>${ui.loginAccount }</span></td>
	</tr>
	</c:forEach>
	
	</tbody>
	</table>
	
	<table>
		<tbody>
		<tr>
		<td>
	    <input type="hidden" name="currentPage" value="${currentPage}" /> 
			<input type="hidden" name="pageCount" value="${pageCount}"/> 
			<input type="hidden" name="count" value="${count}"/>
			<input type="button" name="first1" value="首页" onclick="first()" class="button gray" /> 
			<input type="button" name="pre1" value="上一页" onclick="pre()" class="button green"/> 
			<input type="button" name="next1" value="下一页" onclick="next()" class="button blue"/> 
			<input type="button" name="end1" value="尾页" onclick="end()" class="button gray"/> 
			<font>第${currentPage}页, 共${pageCount}页,共${count}条数据</font>
		</td>
		</tr>
		</tbody>
		</table>
			<table>
		<tbody>
		<tr>
		<td>
		<span>分配方式：<select id="fenpeiType" name="fenpeiType"  style="width: 10%"> 
		       <option id="fenpeiType_1" value="1" >统一平均分配</option>
		       <option id="fenpeiType_2" value="2" >选人分配</option>
			   </select></span> 
	  
	   <span id="isShowFenpeiUser">分配给：<select id="setcustomid" name="setcustomid"  style="width: 10%"> 
		      <c:forEach var="kf" items="${userlist}">
		       <option id="customname_${kf.id}" value="${kf.id}" <c:if test="${setcustomid eq kf.id}">selected</c:if>>${kf.userName}</option>
			   </c:forEach>
		       </select></span> 
		    
		       
		       <input type="button"   onclick="setData()" value="确认分配"/>
		</td>
		</tr>
		</tbody>
		</table>
	</form>	
</div>
<script type="text/javascript">
$(function(){
	//全选
	  $("#allbox_for_requ").click(function(){
	    	if(this.checked){
	    	$("input[name='requ_select']").prop("checked",true);
	    	}else{
	    		$("input[name='requ_select']").prop("checked",false);
	    	}
	    });
	    
	    $("input[name='requ_select']").click(function(){
	    	var chkAllNum=$("input[name='requ_select']").size(); //选项总个数
	    	var chkSelectNum=0;
	    	$("input[name='requ_select']").each(function(i){
	    		if($(this).prop("checked")==true){
	    			chkSelectNum++;
	    		}
	    	});
	    	if(chkAllNum==chkSelectNum){
	    		//全选
	    		$("#allbox_for_requ").prop("checked",true);
	    	}else{
	    		//非全选
	    		$("#allbox_for_requ").prop("checked",false);
	    	}
	    });
	    //选择分配方式
	   $("#isShowFenpeiUser").hide();
	   $("#fenpeiType").change(function(){
		   var fenpeiType=$("#fenpeiType").val();
		   if(fenpeiType=='2'){
		   $("#isShowFenpeiUser").show();
		   }else{
			   $("#isShowFenpeiUser").hide(); 
		   }
   	   
   	});
});	





$(function(){init();Test();});
	function init() {
		var page = parseInt(document.form.currentPage.value);
		var pageCount = parseInt(document.form.pageCount.value);
		var count=parseInt(document.form.count.value);
		if (page == 1 && pageCount!=1) {
			document.form.pre1.disabled = "disabled";
			return;
		}
		if (page == count && pageCount!=1) {
			document.form.next1.disabled = "disabled";
			return;
		}
		if (pageCount == 1) {
			document.form.pre1.disabled = "disabled";
			document.form.next1.disabled = "disabled";
			document.form.first1.disabled = "disabled";
			document.form.end1.disabled = "disabled";
			return;
		}
	} 

	function first() {
		window.location.href = "<%=request.getContextPath()%>/riskManage/getwhkList.do?currentPage=1"+getQueryData();
		
	}

	function next() {
		var page = parseInt(document.form.currentPage.value);
		window.location.href = "<%=request.getContextPath()%>/riskManage/getwhkList.do?currentPage="
				+ (page + 1)+getQueryData();
	}

	function pre() {
		var page = parseInt(document.form.currentPage.value);
		window.location.href = "<%=request.getContextPath()%>/riskManage/getwhkList.do?currentPage="
				+ (page - 1)+getQueryData();
	}

	function end() {
		var pageCount = parseInt(document.form.pageCount.value);
		window.location.href = "<%=request.getContextPath()%>/riskManage/getwhkList.do?currentPage="
				+ pageCount+getQueryData();
	}
	//清除筛选条件
	function clearData(){
		$("#userName").val("");
		
		
	}
	
	//拼接查询条件
	function getQueryData(){
		var userName=$("#userName").val();
		var queryper="&userName="+userName
		return queryper;
		}
	//当指针放到行上触发事件并加深背景色
	 function Test(){  
		 var rows=document.getElementById("userinfotable").rows;  
		   if(rows.length>0){  
	            for(var i=1;i<rows.length;i++){  
	                var obj=rows[i];  
	                obj.onmouseover=function(){
	                	$(this).addClass("backcolor").siblings("tr").removeClass("backcolor")
	                };
	                obj.onclick=function(){
	                	var uid=$(this).children().eq(0).text();
	                	var userphone=$(this).children().eq(3).text();
	                    //location.href="<%=request.getContextPath()%>/custom/getUserselfinfo.do?uid="+uid+"&userphone="+userphone;
	                	location.reload;	
	               };  
	               
	            }  
	        }   
	    }  
	
		//手动分配
		function setData(){
		  if(confirm("确定分配吗?"))
				    {
			         var fenpeiType=$("#fenpeiType").val();
			         if(fenpeiType=='2'){
				     var ordernos="'";
			 	     var selectNum=$("input[name='requ_select']:checked").size();
			 	     if(selectNum==0){
			 		   alert("请至少选择一个客户!");
			 		   return false;
			 	       }
			 	       $("input[name='requ_select']").each(function(i){
			    		if($(this).prop("checked")==true){
			    			ordernos+=$(this).val()+"','";
			    		}
			    	   });
			 	      ordernos=ordernos.substring(0,ordernos.length-2);
			 	        if($("#setcustomid").val()=='0'){
			 	    	   alert("请选择要分配的人！");
			 	    	   return false;
			 	       }
			         }
			 	       $.ajax({
					   type: "post",
					   url: "<%=request.getContextPath()%>/riskManage/setTaskbyhander.do",
					   data: {"fenpeiType":fenpeiType,"ordernos":ordernos,"setcustomid":$("#setcustomid").val(),"setcustomName":$("#setcustomid").find("option:selected").text()},
					   success: function(data){
						 var obj = JSON.parse(data);
						 if(obj.state=="success"){
					    	 alert("分配成功！");
					    	 window.location.href="<%=request.getContextPath()%>/riskManage/getwhkList.do?currentPage=1";
					    	}else{
					    	 alert("分配失败！");
					     }
					   }
					});  
				 }
		 } 

	</script>
</body>
</html>